/**
*      author: Y_Yao
*      created: 2024-09-14 21:12:57
**/

#include<bits/stdc++.h>

using namespace std;

void solve()
{
    int x,y,k;
    cin>>x>>y>>k;

    long long rety = 0,retx = 0;

    if(y % k) rety = y / k + 1;
    else rety = y / k;

    if(x % k) retx = x / k + 1;
    else retx = x / k;

    long long tmp = abs(rety - retx);
    if(retx > rety) retx--;
    
    cout << rety + retx  + tmp << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 0;
    cin >> t;
    //t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}
